<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%@ include file="/jsplib/pubhead.jsp"%>
<%@ page import="net.comm.common.ValueMaping" %>
<%@ taglib uri="/WEB-INF/myTaglib.tld" prefix="tag"%>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<meta http-equiv="x-ua-compatible" content="ie=7" />
	<TITLE>自助机构管理</TITLE>
	<link rel="stylesheet" type="text/css" href="${cpath}/css/adgloab.css"/>
	<link rel="stylesheet" type="text/css" href="${cpath}/css/adstyle.css" />

</head>
<body>
<script> 
	//转页面
	var curUserID = '${userID}';
	if((curUserID == "")||(curUserID == null)){
		parent.window.location.replace("${cpath}/index.jsp"); 
	}
	function change_width(img_name,wid,hei)
	{
		var CurImage=new Image();
		if(CurImage.src!=img_name.src)
		{
			CurImage.src=img_name.src;
		}
		var img_width = CurImage.width;
		var img_height = CurImage.height;
		img_name.width = img_width;
		img_name.height = img_height;

		if(img_height/hei > img_width/wid)
		{
			if( img_height > hei)
			{
				img_name.width = img_name.width/img_name.height*hei;
				img_name.height = hei;
			}
		}
		else
		{
			if( img_width > wid)
			{
				img_name.height = img_name.height/img_name.width*wid;
				img_name.width = wid;
			}
		}
		return true;
	}
</script>

		<DIV id=admin>

		<!-- 右侧宽栏 {{{ -->
		<DIV class=group_mid>

				<div class='subtop' >
					<p><a ><img src="${cpath}/images/slogo.png" ></a></p>
					<dl >
						<dt class="tit">自助机构管理</a></dt>
						<dd class="intro"><span>&nbsp;</span></dd>
					</dl>
					<div class='fun'>
						<li><a href="javascript:history.go(-1);">返回上一页</a></li>
					</div>
				</div>

			<DIV class='whole'><!-- 右侧宽栏 }}}-->
				<form action="${cpath}/group.do" name="theForm"  method="post" enctype="multipart/form-data" >
					<UL class=detailinfo>
						<LI><STRONG>机构名称:</STRONG><EM>
							<input type="text" name='name' value='${theForm.name}' maxlength="100" class="long"/></EM></LI>
						<LI><STRONG>机构介绍:</STRONG><EM>
							<textarea name="subject" rows="8" cols="55" >${theForm.subject}</textarea></EM></LI>
						<LI><STRONG>所在地区:</STRONG><EM>
						<tag:CNPCA name="work_location" id="work_location" pid="0" cid="0" value='${theForm.work_location}'   onchange="getAjaxdata('cnpid',this.value)" onkeydown="catch_keydown(this);" />
						<div id=cnpid style="display:inline">
						<tag:CNPCA name="work_sublocation" pid="${theForm.work_location}" cid="0" value='${theForm.work_sublocation}'  onchange="getAjaxdata('cncid',this.value)" onkeydown="catch_keydown(this);"/>
						</div>
						<div id=cncid style="display:inline">
						<tag:CNPCA name="work_Area" id="work_Area" cid="${theForm.work_sublocation}"  value='${theForm.work_Area}'  onkeydown="catch_keydown(this);" /></div>
						<!--<div id=villagediv style="display:inline">
						<select name='villageID' onkeydown='catch_keydown(this);'></select></div>
						小区&nbsp;&nbsp;-->			
						</EM></LI>

						<!--隐藏域-->
						<INPUT id=max_file_size type=hidden value=2048152 name=MAX_FILE_SIZE>
						<IMG id=oFileChecker style="WIDTH: 0px; HEIGHT: 0px" onload=check_photo_size()> 
						<LI><STRONG>机构照片:</STRONG><EM>
							<input type="file" name='picFile' value='' class="long" onchange="check_fileszie(this);"/>&nbsp;*支持文件格式：.jpg/.jpeg/.gif<br>
							<!--<img src="${cpath}/${theForm.pic}" onload="change_width(this,500,500)">-->
							</EM></LI>						
						
						<input type="hidden" name='userID'	value='${theForm.userID}'/>
						<input type="hidden" name='groupID' value='${theForm.groupID}'/>
						<input type="hidden" name='firsort' value='${theForm.firsort}'/>
						<input type="hidden" name='secsort' value='${theForm.secsort}'/>
						<input type="hidden" name='thiSort' value='${theForm.thiSort}'/>
						<input type="hidden" name='pic'		value='${theForm.pic}'/>
						<input type="hidden" name='joinNum' value='${theForm.joinNum}'/>
						<input type="hidden" name='num'		value='${theForm.num}'/>
						<input type="hidden" name='type'	value='${theForm.type}'/>
						<input type="hidden" name='ctime'	value='${theForm.ctime}'/>
						<input type="hidden" name='pepoleVal'	value='${theForm.pepoleVal}'/>
						<input type="hidden" name='partakeVal'	value='${theForm.partakeVal}'/>
						<input type="hidden" name='contrVal'	value='${theForm.contrVal}'/>
						<input type="hidden" name='useAlbumSize'value='${theForm.useAlbumSize}'/>
						<input type="hidden" name='albumSize'	value='${theForm.albumSize}'/>
						<input type="hidden" name='status'		value='${theForm.status}'/>
						<input type="hidden" name='action'		value='${theForm.action}'/>
					</UL><!--结束 }}}-->
					<UL class=detailinfo>
						<li class=btn>	
							<input type="button" name="save"  onclick="javascript:doConfirm();" class="shortBtn" value="保   存"/>&nbsp;
						</li>
					</UL>
				</form>
			</DIV><!-- whole end }}} -->			

		</DIV><!-- profile_mid }}} -->
		</DIV><!-- group end }}} -->

</body>
</html>
<!---->

<script>

  /**
   * 检查项目资料维护
   */
	function doConfirm()
	{
		var form = document.theForm;

		var subject = form['subject'];
		var name = form['name'];
		var type = form['type'];
		var action = form['action'];

		if(name.value == null||name.value.replace(/(^\s*)|(\s*$)/g,"").length < 1)
  		{
			alert('名称不能为空');
			name.select();
			return ;
		}
		if(subject.value.length > 200)
		{
			alert('机构介绍长度不能大于200');
			subject.select();
			return ;
		}

		var work_location = form['work_location'];
		if(work_location.value == null||work_location.value == ""||work_location.value == "0")
		{
			alert('请选择所在省份');
			work_location.select();
			return ;
		}
		var work_sublocation = form['work_sublocation'];
		if(work_sublocation.value == null||work_sublocation.value == ""||work_sublocation.value == "0")
		{
			alert('请选择所在城市');
			work_sublocation.select();
			return ;
		}

		/**/
		var picFile = form['picFile'];
		if(picFile.value !="" && !check_fileszie(picFile))
			return;
		
		form.submit();
	}

	function my_getbyid(id)
	{
		 itm = null;
		 if (document.getElementById)
		 {
				itm = document.getElementById(id);
		 }
		 else if (document.all)
		 {
				itm = document.all[id];
		 }
		 else if (document.layers)
		 {
				itm = document.layers[id];
		 }	 
		 return itm;
	}

	function check_fileszie(filePicker)
	{
			var patn = /.jpg$|.jpeg$|.gif$/i;  
			if(patn.test(filePicker.value)) {
					img_temp = my_getbyid('oFileChecker');
					img_temp.src = filePicker.value;
			} else {
						alert('您选择的不是合法的图片文件,支持文件格式：.jpg/.jpeg/.gif，请重新选择');
						filePicker.value='';
						return false;
			}
			return true;
	}	
	function check_photo_size()
	{
			img_temp = my_getbyid('oFileChecker');
			var limit = parseInt(my_getbyid('max_file_size').value);
			if (img_temp.fileSize > limit) {
					alert("照片文件过大，请选择2M以下的文件上传");
					return false;
			}
	}

	function my_getbyid(id)
	{

		 itm = null;
		 if (document.getElementById)
		 {
				itm = document.getElementById(id);
		 }
		 else if (document.all)
		 {
				itm = document.all[id];
		 }
		 else if (document.layers)
		 {
				itm = document.layers[id];
		 }
		 
		 return itm;
	}

	/**
    * 
    */
	function getVillage(div,id)
	{

		var xmlHttp;
		start = true;
		try
		{    // Firefox, Opera 8.0+, Safari    
			xmlHttp=new XMLHttpRequest();
		}
		catch (e)
		{    // Internet Explorer    
			try
			{
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e)
			{
				try
				{
					xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e)
				{
					alert("Your browser does not support AJAX!");
					return false;
				}
			}
		}
		var url;
		
		url = "${cpath}/shequ/getVillage.jsp?work_area=" + id ;
		my_getbyid(div).innerHTML="<select name='villageID' onkeydown='catch_keydown(this);'></select>";
		if (start)
		{
			my_getbyid(div).innerHTML='后台取数据……';
			xmlHttp.onreadystatechange=function()
			{
				if(xmlHttp.readyState==4 && xmlHttp.status==200)
				{
					var ret_str = xmlHttp.responseText;

					var secsort = "<select name='villageID' onkeydown='catch_keydown(this);'>" +
							ret_str.replace(/(^\s*)|(\s*$)/g,"") + "</select>";
					my_getbyid(div).innerHTML = secsort;
				}
			}
			xmlHttp.open("GET",url,true);
			xmlHttp.send(null);
		}
	}

	function getAjaxdata(div,id)
	{

		var xmlHttp;
		start = true;
		try
		{    // Firefox, Opera 8.0+, Safari    
			xmlHttp=new XMLHttpRequest();
		}
		catch (e)
		{    // Internet Explorer    
			try
			{
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e)
			{
				try
				{
					xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e)
				{
					alert("Your browser does not support AJAX!");
					return false;
				}
			}
		}
		var url;
		if(div =="divsecsort"){

			url = "${cpath}/param/getproperty.jsp?assortID=2&parentID=" + id ;

		}else if(div =="cnpid" ){
		
			url = "${cpath}/param/getCnpid.jsp?pid=" + id ;
			my_getbyid("cncid").innerHTML="<select name='work_Area' onkeydown='catch_keydown(this);'></select>";
		}else if(div =="homepid" ){
		
			url = "${cpath}/param/getCnpid.jsp?pid=" + id ;
			my_getbyid("homecid").innerHTML="<select name='home_Area' onkeydown='catch_keydown(this);'></select>";
		}else {

			url = "${cpath}/param/getCncid.jsp?cid=" + id;
		}
		if (start)
		{
			my_getbyid(div).innerHTML='后台取数据……';
			xmlHttp.onreadystatechange=function()
			{
				if(xmlHttp.readyState==4 && xmlHttp.status==200)
				{
					var ret_str = xmlHttp.responseText;
					if(div =="divsecsort"){
						var secsort = "<select name='secsort' onkeydown='catch_keydown(this);'>" +
							ret_str.replace(/(^\s*)|(\s*$)/g,"") + "</select>"
						my_getbyid(div).innerHTML = secsort;

					}else if(div =="cnpid"){

						var secsort = "<select name='work_sublocation' onkeydown='catch_keydown(this);'" +
							" onChange=\"getAjaxdata('cncid',this.value)\">" + 
							ret_str.replace(/(^\s*)|(\s*$)/g,"") + "</select>"
						my_getbyid(div).innerHTML = secsort;

					}else if(div =="homepid"){

						var secsort = "<select name='home_sublocation' onkeydown='catch_keydown(this);'" +
							" onChange=\"getAjaxdata('homecid',this.value)\">" + 
							ret_str.replace(/(^\s*)|(\s*$)/g,"") + "</select>"
						my_getbyid(div).innerHTML = secsort;

					}else if(div =="homecid"){

						var secsort = "<select name='home_area' id='home_area' onkeydown='catch_keydown(this);'>" +
							ret_str.replace(/(^\s*)|(\s*$)/g,"") + "</select>"
						my_getbyid(div).innerHTML = secsort;

					}else{
						var secsort = "<select name='work_Area' id='work_Area' onkeydown='catch_keydown(this);' >" +
							ret_str.replace(/(^\s*)|(\s*$)/g,"") + "</select>"
						my_getbyid(div).innerHTML = secsort;
					}
				}
			}
			xmlHttp.open("GET",url,true);
			xmlHttp.send(null);
		}
	}

	/**
	 * 根据具体请求设置各个组件状态	
     */
	function showState()
	{
		var action = '${theForm.action}';
		var form = document.theForm;		
		if(action == 'detail')
		{
           
		}
		else if(action == 'adoper' || action == 'update')
		{
			form['action'].value = 'adupdate';
		}else{

			form['action'].value = 'adadd';
		}
	}
	showState();

</script>

